home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 10 / FM Towns Free Software Collection 10.iso / ms_dos / tool / dprint / dp_main.c < prev    next >
Text File  |  1995-01-01  |  3KB  |  165 lines

  1. /*
  2.  
  3. 8086|Printman/POSTCARD エディタモジュール
  4. Copyright (c) 1993,94 Delmonta
  5.  
  6. */
  7.  
  8. #include<farstr.h>
  9. #include"dprint.h"
  10.  
  11. struct POSTCARD far *Card[MAXCARD];
  12. unsigned    Cardnum;
  13. unsigned    Cardpos;
  14. int        Ypos;
  15.  
  16. /*---------------------------------------------------------------------------*/
  17.  
  18. static    bool    newcard(void)
  19. {
  20.     if    (Cardpos==Cardnum)
  21.     {
  22.         if    (!addcard(Cardpos))
  23.             return FALSE;
  24.         else
  25.         {
  26.             Cardnum++;
  27.             dp_putcardnum();
  28.             printf("\033[%d;33f",Ypos+7);
  29.         }
  30.     }
  31.     return TRUE;
  32. }
  33.  
  34. /*---------------------------------------------------------------------------*/
  35.  
  36. static    void    menu_patch(void)
  37. {
  38.     char    buf[25];
  39.  
  40.     if    (Cardpos < Cardnum)
  41.         far_strcpy(buf,Card[Cardpos]->data[Ypos]);
  42.     else
  43.         buf[0] = '\0';
  44.  
  45.     if    (strinput(buf,24))
  46.     {
  47.         if    (newcard())
  48.         {
  49.             far_strcpy(Card[Cardpos]->data[Ypos],buf);
  50.             Changedflag = TRUE;
  51.         }
  52.     }
  53. }
  54.  
  55. /*---------------------------------------------------------------------------*/
  56.  
  57. static    void    menu_inputzipcode(void)
  58. {
  59.     int    buf[5];
  60.     int    i = 0;
  61.     char    c;
  62.  
  63.     printf("   -  \b\b\b\b\b\b");
  64.  
  65.     while(1)
  66.     {
  67.         c = dp_getch();
  68.  
  69.         if    (c=='\b' && i>0)            /* BSキー */
  70.         {
  71.             i--;
  72.  
  73.             if    (i == 2)
  74.                 printf("\b\b  \b\b");
  75.             else
  76.                 printf("\b \b");
  77.         }
  78.         else if    ('0'<=c && c<='9' && i<5)    /* 数字キー */
  79.         {
  80.             putchar(c);
  81.             buf[i++] = (int)c-'0';
  82.                 if    (i==3)
  83.                     putchar('-');
  84.         }
  85.         else if    (c=='\r' && (i==0 || i==3 || i==5))
  86.         {
  87.             if    (!newcard())
  88.                 return;
  89.  
  90.             if    (i==0)
  91.                 Card[Cardpos]->zipcode[0] = -1;
  92.             else
  93.             {
  94.                 Card[Cardpos]->zipcode[0]
  95.                     = buf[0]*100 + buf[1]*10 + buf[2];
  96.  
  97.                 if    (i==3)
  98.                     Card[Cardpos]->zipcode[1] = -1;
  99.                 else
  100.                     Card[Cardpos]->zipcode[1]
  101.                         = buf[3]*10 + buf[4];
  102.             }
  103.  
  104.             Changedflag = TRUE;
  105.             return;
  106.         }
  107.         else if    (c=='\033')
  108.             return;
  109.         else
  110.             putchar('\a');
  111.     }
  112. }
  113.  
  114. /*---------------------------------------------------------------------------*/
  115.  
  116. void    dp_main(void)
  117. {
  118.     char    c;
  119.  
  120.     Ypos = -1;
  121.  
  122. dpmain_keyrep:
  123.  
  124.     printf("\033[%d;33f\033[7;37m",Ypos+7);
  125.     card_reshow(1<<(Ypos+1));
  126.     printf("\033[0;37m\033[%d;33f",Ypos+7);
  127.  
  128.     switch    ( c=dp_getch())
  129.     {
  130.     case UPKEY:
  131.         if    (Ypos > -1)
  132.         {
  133.             card_reshow(1<<(Ypos+1));
  134.             Ypos--;
  135.         }
  136.         break;
  137.  
  138.     case DOWNKEY:
  139.         if    (Ypos < 4)
  140.         {
  141.             card_reshow(1<<(Ypos+1));
  142.             Ypos++;
  143.         }
  144.         break;
  145.  
  146.     case EXTKEY_H:
  147.         dp_funcmenu();
  148.         break;
  149.  
  150.     default:
  151.         if    (c<' ')
  152.             putchar('\7');
  153.         else
  154.         {
  155.             dp_ungetch(c);
  156.             if    (Ypos>=0)
  157.                 menu_patch();
  158.             else
  159.                 menu_inputzipcode();
  160.         }
  161.         break;
  162.     }
  163.     goto dpmain_keyrep;
  164. }
  165.